package cn.itcast.anli.web;

import cn.itcast.anli.domain.Employee;
import cn.itcast.anli.service.EmployeeService;
import cn.itcast.anli.service.impl.EmployeeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findServlet")
public class FindServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("utf-8");
        //获取员工id
        String id = request.getParameter("id");
        //调用Service对象的相关方法
        EmployeeService service = new EmployeeServiceImpl();
        Employee employee = service.findById(Integer.parseInt(id));
        //查找到对象之后，将其传进request域中
        request.setAttribute("employee",employee);
        request.getRequestDispatcher("/modify.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
